package java_class_work.week02;

import java.util.Arrays;
import java.util.Scanner;

public class Demo05 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        //总人数n
        int n = scanner.nextInt();
        //第k个人开始
        int k = scanner.nextInt();
        //报到 m 的淘汰
        int m = scanner.nextInt();
        int[] people = Methed02(n, k, m);
        for (int i : people) {
            if (i != 0) {
                System.out.println("最后剩下了" + i + "号！");
            }
        }
    }

    public static int[] Methed01(int n, int k, int m) {
        int[] people = new int[n];
        //编号
        for (int i = 0; i < n; i++)
            people[i] = i + 1;
        System.out.println(Arrays.toString(people));
        int num = 0;
        for (int i = k - 1; ; i = i == people.length - 1 ? 0 : i + 1) {
            //当只剩下一个人时
            if (n == 1) break;
            //淘汰的跳过
            if (people[i] == 0) continue;
            // 报数
            num++;
            if (num == m) {
                System.out.println(people[i] + "号报到"+m+"，"+people[i] + "号淘汰！");
                people[i] = 0;
                n--;
                num = 0;
            }
        }
        return people;
    }

    public static int[] Methed02(int n, int k, int m) {
        int[] people = new int[n];
        //编号
        for (int i = 0; i < n; i++)
            people[i] = i + 1;
        System.out.println(Arrays.toString(people));
        int num = 0,index;
        for (int i = k - 1; ; i++) {
            //当只剩下一个人时
            if (n == 1) break;
            //淘汰的跳过
            index = i%people.length;
            if (people[index] == 0) continue;
            // 报数
            num++;
            if (num == m) {
                System.out.println(people[index] + "号报到"+m+"，"+people[index] + "号淘汰！");
                people[index] = 0;
                n--;
                num = 0;
            }
        }
        return people;
    }
}
